﻿// -----------------------------------------------------------------------
// <copyright file="Pushover.cs" company="The Usual Dosage">
// © 2013 by Matthew M. Martin
// </copyright>
// -----------------------------------------------------------------------

namespace Cadence.NET.TestConsole
{
    using System.Threading;

    /// <summary>
    /// Creates a spinner on the console when an app is waiting. Just for fun.
    /// </summary>
    public class ConsoleSpinner
    {
        #region Private Members

        int counter;
        
        #endregion Private Members

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="ConsoleSpinner"/> class.
        /// </summary>
        public ConsoleSpinner()
        {
            counter = 0;
        }

        #endregion Constructor

        #region Public Methods

        /// <summary>
        /// Turns the spinner
        /// </summary>
        public void Turn()
        {
            counter++;
            switch (counter % 4)
            {
                case 0: System.Console.Write("/"); break;
                case 1: System.Console.Write("-"); break;
                case 2: System.Console.Write("\\"); break;
                case 3: System.Console.Write("|"); break;
            }
            System.Console.SetCursorPosition(System.Console.CursorLeft - 1, System.Console.CursorTop);
            Thread.Sleep(500);
        }

        #endregion Public Methods
    }
}
